<!--
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-07-15 15:33:47
-->
<template>
  <div>
    <el-card>
      <CategoryView :display="showView" />
    </el-card>
    <el-card class="cardTop">
      <SpuList v-if="showView === 1" @set-state="getState" />
      <SpuFrom v-if="showView === 2" :spuId="spuId" @set-state="getState" />
      <SkuFrom v-if="showView === 3" :spuId="spuId" @set-state="getState" />
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import SpuList from './SpuList/index.vue'
import SpuFrom from './SpuFrom/index.vue'
import SkuFrom from './SkuFrom/index.vue'
import { ref } from 'vue'
import type { IReqSpuListRecord } from '@/types/spu'

// 定义显示的视图
const showView = ref(1)

const spuId = ref<string | number>('')

// 自定义事件
const getState = (stateId: number, row?: IReqSpuListRecord) => {
  showView.value = stateId

  row?.id ? (spuId.value = row.id) : (spuId.value = '')
}
</script>

<script lang="ts">
export default {
  name: 'SpuView'
}
</script>

<style lang="scss" scoped>
.cardTop {
  margin-top: 18px;
}
</style>
